package com.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.mapper.SysMenuMapper;
import com.pojo.SystemMenu;
import com.util.TreeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TestController {
    @Autowired
    SysMenuMapper sysMenuMapper;

    @ResponseBody
    @RequestMapping("/test")
    public String test() {
        List<SystemMenu> menu = sysMenuMapper.findAllByStatusOrderBySort(1);
        List<SystemMenu> systemMenus = TreeUtil.toTree(menu, 0);
        Map<String,Object> loginfo= new HashMap<String, Object>();
        loginfo.put("title","王事成");
        loginfo.put("href","#");
        loginfo.put("image","images/logo.png");
        Map<String,Object> homeinfo= new HashMap<String, Object>();
        homeinfo.put("title","首页");
        homeinfo.put("href","page/welcome-2.jsp?t=1");
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("logoInfo",loginfo);
        map.put("homeInfo",homeinfo);
        map.put("menuInfo",systemMenus);
        return JSON.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping("/home")
    public String home(){
        return "/layuimini/index.jsp";
    }

}
